var datatable;// 定义一个全局的dataTable
var alarmChar;


var param = new Object({
	init:function(){
		this.beginDate = ''
		this.endDate = ''
		this.dimension = ''
		this.condition = ''
		this.sgw = ''
	    this.enodebid = ''
		this.cell = ''
	},
	setDimensionParam:function(dimension){
		switch(dimension) {
			case 'r_sgw' :
				this.sgw=$('#sgw').val()
				break
			case 'r_enodeb' :
				this.enodebid =$('#eNodeBID').val()
				break
			case 'r_cell' :
				  this.cell =$('#cell_id').val()
				  break
		}
	},
	setParam:function(){
		this.init()
		this.beginDate = $('#beginDate').val()
		this.endDate = $('#endDate').val()
		//this.netType = $('#_4g').val()
		this.condition = $('input:radio[name="condition"]:checked').val();
		this.dimension = $('input:radio[name="ab"]:checked').val();
		this.cell =$('#cell_id').val();
		this.setDimensionParam(this.dimension)
	}
});


$(function() {
	
	$("#sgw").combobox();
	
	$('#table tbody').on('click', 'tr', function() {
		if ($(this).hasClass('selected')) {
			$(this).removeClass('selected');
		} else {
			datatable.$('tr.selected').removeClass('selected');
			$(this).addClass('selected');
		}
	});
	//checkAlarm();
	alarmChar = echarts.init(document.getElementById('alarmChar'));
})


function getSelectRadio() {
	var selectedvalue = $("input[name='condition']:checked").val();
	
	for (var i = 0; i < 2; i++) {
		var tempId = '#radio_' + i;
		var tempTimeId = '#radioTime_' + i;
		if (selectedvalue == i) {
			$(tempId).show();
			$(tempTimeId).show();
		} else {
			$(tempId).hide();
			$(tempTimeId).hide();
		}
	}
	
}


var timeOut; 

function initAlarm(){
	initAlarmCharChar();
	getHistoryList();
	if("min"== $('input:radio[name="timeSize"]:checked').val())
	 timeOut=setTimeout("initAlarm()",1000*60);
	else{
		timeOut=setTimeout("initAlarm()",1000*60*60);
	}
	
}

function stopAlarm()
{
  clearTimeout(timeOut);
}

function checkAlarm(){
	//initAlarmCharChar();
	getHistoryList();
}


function initAlarmCharChar() {
	

	param.setParam();
	
	// 查询
	alarmChar.clear();
	alarmChar.showLoading({
		text : '正在努力的读取数据中...'
	});
	
	$.ajax({
		type : "POST",
		url : "../../kpi/qwalarm/getAlarmDiag?rand="
				+ Math.random(),
		dataType : "json",
		"data" : {
			"param" : JSON.stringify(param)
		},
		success : function(data) {
			alarmChar.setOption(data, true);
			alarmChar.hideLoading();
		}
	});
}



function getHistoryList() {
	
//	var startTime=$("#beginDate").val();  
//    var endTime=$("#endDate").val();  
//    if(!checkEndTime()){
//		layer.alert("开始时间不能大于结束时间！", {
//			icon : 3,
//			offset: '100px'
//		});
//		return;
//	};
	
	//第二版变更开始**********
	param.setParam();
	
	//第二版变更结束**********
	$("#table tbody tr").remove();
	if (datatable == undefined || datatable == "undefined" || datatable == null) {
	} else {
		datatable.destroy();
	}
	datatable = $('#table')
			.DataTable(
					{
						"aoColumnDefs" : [ {
							sDefaultContent : '',
							aTargets : [ '_all' ]
						} ],
						"bPaginate" : true, // 翻页功能
						"bLengthChange" : false, // 改变每页显示数据数量
						"bFilter" : false, // 过滤功能
						"ordering": true, //排序功能
						"bSort" : true, // 排序功能
						"bInfo" : true,// 页脚信息
						"bAutoWidth" : true,// 自动宽度
						"iDisplayLength" : 50,
						// "sPaginationType": "full_numbers",//显示分页的样式
						// 还有simple_numbers等
						"sScrollX" : "100%",
						"sScrollXInner" : "110%",
						"bScrollCollapse" : true,
						"oLanguage" : {
							"sLengthMenu" : "每页显示 _MENU_条",
							"sZeroRecords" : "没有找到符合条件的数据",
							"sProcessing" : "&nbsp;&nbsp;&nbsp;&nbsp;查询中，请稍等...",
							"sInfo" : "当前第 _START_ - _END_ 条　共计 _TOTAL_ 条",
							"sInfoEmpty" : "没有记录",
							"sInfoFiltered" : "(从 _MAX_ 条记录中过滤)",
							"sSearch" : "搜索：",
							"oPaginate" : {
								"sFirst" : "首页",
								"sPrevious" : "前一页",
								"sNext" : "后一页",
								"sLast" : "尾页"
							}
						},
						"bProcessing" : true,
						"bServerSide" : true,
						"sAjaxSource" : "../../kpi/qwalarm/getAlarmHistory",
						"fnServerData" : function(sSource, aoData, fnCallback) {
							$
									.ajax({
										"type" : "post",
										"contentType" : "application/x-www-form-urlencoded",
										"url" : sSource,
										"dataType" : "json",
										"data" : {
											"aoData" : JSON.stringify(aoData),
											"param" : JSON.stringify(param)
										}, // 以json格式传递
										"success" : function(resp) {
											fnCallback(resp.pageDate);
											d = resp.allData;
										}
									});
						},
						columns : [ {
							data : "start_date"
						}, {
							data : "end_date"
						}, {
							data : "sgw_dev"
						}, {
							data : "target_type"
						}, {
							data : "target_value"
						}, {
							data : "alarm_level"
						}]
	});
}


function resetForm(){
	$('#queryForm').reset(); 
}

function forwordSignalBack(phoneNumber,beginDate,endDate){
	var url="/kpi/signalBackTrack/index?phoneNumber="+phoneNumber+"&beginDate="+beginDate+"&endDate="+endDate+"";
//	window.location.href=url;
	linkTab("信令回溯", url);
}

